home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / manifest_array.e < prev    next >
Text File  |  1998-01-16  |  9KB  |  447 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class MANIFEST_ARRAY
  17.    --
  18.    -- Like :  << foo , bar >>
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.    
  23. creation make
  24.    
  25. feature 
  26.    
  27.    start_position: POSITION; 
  28.      -- Of first character '<'.   
  29.  
  30.    list: ARRAY[EXPRESSION];
  31.      -- Void or elements in the array.
  32.    
  33.    result_type: TYPE_ARRAY;
  34.      -- Computed according to the actual `list'.
  35.    
  36.    make(sp: like start_position; l: like list) is
  37.       require
  38.      sp /= Void;
  39.      l /= Void implies not l.empty and l.lower =1;
  40.       do
  41.      start_position := sp;
  42.      list := l;
  43.       ensure
  44.      start_position = sp;
  45.      list = l;
  46.       end;
  47.    
  48.    precedence: INTEGER is 2;
  49.  
  50.    is_static: BOOLEAN is false;
  51.    
  52.    can_be_dropped: BOOLEAN is false;
  53.    
  54.    c_simple: BOOLEAN is false;
  55.  
  56. feature
  57.    
  58.    isa_dca_inline_argument: INTEGER is
  59.      -- *** A FAIRE ??? ***
  60.       do
  61.       end;
  62.  
  63.    dca_inline_argument(formal_arg_type: TYPE) is
  64.      -- *** FAIRE ***
  65.       do
  66.       end;
  67.  
  68.    is_pre_computable: BOOLEAN is 
  69.       local
  70.      i: INTEGER;
  71.      e: EXPRESSION;
  72.       do
  73.      if list = Void then
  74.         Result := true;
  75.      elseif result_type.generic_list.item(1).is_string then
  76.         from  
  77.            Result := true;
  78.            i := list.upper;
  79.         until
  80.            not Result or else i = 0
  81.         loop
  82.            e := list.item(i);
  83.            Result := e.is_pre_computable;
  84.            i := i - 1;
  85.         end;        
  86.      end;
  87.       end;
  88.  
  89.    afd_check is 
  90.       local
  91.      i: INTEGER;
  92.       do
  93.      if list /= Void then
  94.         from  
  95.            i := list.upper;
  96.         until
  97.            i = 0
  98.         loop
  99.            list.item(i).afd_check;
  100.            i := i - 1;
  101.         end;        
  102.      end;
  103.       end;
  104.    
  105.    frozen mapping_c_target(target_type: TYPE) is
  106.       do
  107.      cpp.put_character('(');
  108.      cpp.put_character('(');
  109.      cpp.put_character('T');
  110.      cpp.put_integer(target_type.id);
  111.      cpp.put_character('*');
  112.      cpp.put_character(')');
  113.      compile_to_c;
  114.      cpp.put_character(')');
  115.       end;
  116.  
  117.    frozen mapping_c_arg(formal_arg_type: TYPE) is
  118.       do
  119.      compile_to_c;
  120.       end;
  121.  
  122.    compile_to_c is
  123.       local
  124.      i: INTEGER;
  125.      formal_type, actual_type: TYPE;
  126.      adr: BOOLEAN;
  127.      e: EXPRESSION;
  128.       do
  129.      manifest_array_pool.c_call(result_type);
  130.      formal_type := result_type.generic_list.item(1).run_type;
  131.      cpp.put_character('(');
  132.      if list = Void then
  133.         cpp.put_character('0');
  134.      else
  135.         adr := formal_type.is_user_expanded; 
  136.         cpp.put_integer(list.upper);
  137.         from  
  138.            i := 1;
  139.         until
  140.            i > list.upper
  141.         loop
  142.            cpp.put_character(',');
  143.            if adr then
  144.           cpp.put_character('&');
  145.            end;
  146.            e := list.item(i);
  147.            actual_type := e.result_type.run_type;
  148.            if formal_type.is_reference and then actual_type.is_expanded then
  149.           actual_type.to_reference;
  150.           cpp.put_character('(');
  151.           e.compile_to_c;
  152.           cpp.put_character(')');
  153.            else
  154.           e.compile_to_c;
  155.            end;
  156.            i := i + 1;
  157.         end;        
  158.      end;
  159.      cpp.put_character(')');
  160.       end;
  161.    
  162.    compile_to_c_old is 
  163.       local
  164.      i: INTEGER;
  165.       do 
  166.      if list /= Void then
  167.         from  
  168.            i := list.upper;
  169.         until
  170.            i = 0
  171.         loop
  172.            list.item(i).compile_to_c_old;
  173.            i := i - 1;
  174.         end;        
  175.      end;
  176.       end;
  177.  
  178.    compile_to_jvm_old is 
  179.       local
  180.      i: INTEGER;
  181.       do 
  182.      if list /= Void then
  183.         from  
  184.            i := list.upper;
  185.         until
  186.            i = 0
  187.         loop
  188.            list.item(i).compile_to_jvm_old;
  189.            i := i - 1;
  190.         end;        
  191.      end;
  192.       end;
  193.  
  194.    compile_target_to_jvm, compile_to_jvm is
  195.       local
  196.      rt, elt_type: TYPE;
  197.      i, idx, space: INTEGER;
  198.      rc: RUN_CLASS;
  199.      idx_rc: INTEGER;
  200.      cp: like constant_pool;
  201.      ca: like code_attribute;
  202.       do
  203.      cp := constant_pool;
  204.      ca := code_attribute;
  205.      rt := result_type.run_type;
  206.      rc := rt.run_class;
  207.      elt_type := rt.generic_list.item(1).run_type;
  208.      idx_rc := rc.fully_qualified_constant_pool_index;
  209.      ca.opcode_new(idx_rc);
  210.      -- Set lower :
  211.      idx := cp.idx_fieldref4(idx_rc,us_lower,fz_30);
  212.      ca.opcode_dup;
  213.      ca.opcode_iconst_1;
  214.      ca.opcode_putfield(idx,-2);
  215.      -- Set upper :
  216.      idx := cp.idx_fieldref4(idx_rc,us_upper,fz_30);
  217.      ca.opcode_dup;
  218.      if list = Void then
  219.         ca.opcode_iconst_m1;
  220.      else 
  221.         ca.opcode_push_integer(list.count);
  222.      end; 
  223.      ca.opcode_putfield(idx,-2);
  224.      -- Set capacity :
  225.      idx := cp.idx_fieldref4(idx_rc,us_capacity,fz_30);
  226.      ca.opcode_dup;
  227.      if list = Void then
  228.         ca.opcode_iconst_0;
  229.      else 
  230.         ca.opcode_push_integer(list.count);
  231.      end; 
  232.      ca.opcode_putfield(idx,-2);
  233.      -- Set storage :
  234.      idx := cp.idx_fieldref4(idx_rc,us_storage,sd(elt_type));
  235.      ca.opcode_dup;
  236.      if list = Void then
  237.         ca.opcode_aconst_null;
  238.      else
  239.         ca.opcode_push_integer(list.count);
  240.         elt_type.jvm_xnewarray;
  241.         from
  242.            i := 1;
  243.         until
  244.            i > list.upper
  245.         loop
  246.            ca.opcode_dup;
  247.            ca.opcode_push_integer(i - 1);
  248.            space := list.item(i).compile_to_jvm_into(elt_type);
  249.            elt_type.jvm_xastore;
  250.            i := i + 1;
  251.         end;
  252.      end;
  253.      ca.opcode_putfield(idx,-2);
  254.       end;
  255.    
  256.    jvm_branch_if_false: INTEGER is
  257.       do
  258.       end;
  259.  
  260.    jvm_branch_if_true: INTEGER is
  261.       do
  262.       end;
  263.    
  264.    compile_to_jvm_into(dest: TYPE): INTEGER is
  265.       do
  266.      Result := 1;
  267.      compile_to_jvm;
  268.       end;
  269.  
  270.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  271.       do
  272.       end;
  273.    
  274.    use_current: BOOLEAN is
  275.       local
  276.      i: INTEGER;
  277.       do
  278.      if list /= Void then
  279.         from  
  280.            i := list.upper;
  281.         until
  282.            i = 0 or else Result
  283.         loop
  284.            Result := list.item(i).use_current;
  285.            i := i - 1;
  286.         end;        
  287.      end;
  288.       end;
  289.    
  290.    to_runnable(ct: TYPE): like Current is
  291.       local
  292.      i: INTEGER;
  293.      e: EXPRESSION;
  294.      t: TYPE;
  295.       do
  296.      if current_type = Void then
  297.         current_type := ct;
  298.         if list = Void then
  299.            t := type_any;
  300.         else
  301.            from  
  302.           i := list.upper;
  303.            until
  304.           i = 0
  305.            loop
  306.           e := list.item(i).to_runnable(ct);
  307.           if e = Void then
  308.              eh.add_position(start_position);
  309.              error(list.item(i).start_position,
  310.                "Bad expression in manifest array.");
  311.              i := 0;
  312.           else
  313.              list.put(e,i);
  314.              if t = Void then
  315.             t := e.result_type;
  316.              else
  317.             t := t.smallest_ancestor(e.result_type);
  318.              end;
  319.              i := i - 1;
  320.           end;
  321.            end;
  322.         end;
  323.         if nb_errors = 0 then
  324.            !!result_type.make(start_position,t.run_type);
  325.            result_type := result_type.to_runnable(current_type);
  326.            result_type.run_class.set_at_run_time;
  327.            Result := Current;
  328.            if t.is_reference and then list /= Void then
  329.           from
  330.              i := list.upper;
  331.           until
  332.              i = 0
  333.           loop
  334.              t := list.item(i).result_type;
  335.              if t.is_expanded then
  336.             t.used_as_reference;
  337.              end
  338.              i := i - 1;
  339.           end;
  340.            end;
  341.         end;
  342.      else
  343.         if list = Void then
  344.            !!Result.make(start_position,Void);
  345.         else
  346.            !!Result.make(start_position,list.twin);
  347.         end;
  348.         Result := Result.to_runnable(ct);
  349.      end;
  350.       end;
  351.  
  352.    bracketed_pretty_print is
  353.       do
  354.      fmt.put_character('(');
  355.      pretty_print;
  356.      fmt.put_character(')');
  357.       end;
  358.  
  359.    pretty_print is
  360.       local
  361.      i: INTEGER;
  362.       do
  363.      fmt.put_string(fz_c_shift_left);
  364.      fmt.level_incr;
  365.      if list /= Void then
  366.         from  
  367.            i := 1;
  368.         until
  369.            i > list.upper
  370.         loop
  371.            list.item(i).pretty_print;
  372.            i := i +